<template>
  <div class="box">
    <van-nav-bar
      @click-left="$router.back()"
      title="我的定位"
      left-text="返回"
      left-arrow
    >
      <template #right>
        <van-icon name="manager" size="18" @click="logFn" />
      </template>
    </van-nav-bar>
    <div class="cnontent">
      <van-cell-group>
        <van-field
          label="定位城市:"
          placeholder="定位不准确时，请在城市列表中选择"
          disabled
        />
      </van-cell-group>
      <van-cell :title="locationCity" is-link @click="cityFn" />
    </div>
    <div class="top">
      <h3>热门城市</h3>
      <div class="top_citie">
        <span @click="topFn(item.id)" v-for="item in topCity" :key="item.id">{{
          item.name
        }}</span>
      </div>
    </div>
    <div class="all">
      <h3>所有城市</h3>
      <span>(按字母排序)</span>
      <h1>A</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.A" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>B</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.B" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>C</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.C" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>D</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.D" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>E</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.E" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>F</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.F" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>G</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.G" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>H</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.H" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>J</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.J" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>K</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.K" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>L</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.L" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>M</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.M" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>N</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.N" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>P</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.P" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>Q</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.Q" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>R</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.R" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>S</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.S" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>T</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.T" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>W</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.W" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>X</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.X" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>Y</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.Y" :key="item.id">{{
          item.name
        }}</span>
      </div>
      <h1>Z</h1>
      <div class="all_citie">
        <span @click="btn(item.id)" v-for="item in allCity.Z" :key="item.id">{{
          item.name
        }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { citie } from "@/api/cities.js";
export default {
  data() {
    return {
      citie: "",
      locationCity: "广州", //定位城市
      topCity: "", //热门城市
      allCity: "", //所有城市
      id: 4,
    };
  },
  methods: {
    //点击跳转城市地址页面
    cityFn() {
      this.$router.push({
        path: "/citysite",
        query: {
          id: this.id,
        },
      });
    },
    //点击所有城市
    btn(id) {
      this.$router.push({
        path: "/citysite",
        query: {
          id,
        },
      });
    },
    //点击热门城市
    topFn(id) {
      this.$router.push({
        path: "/citysite",
        query: {
          id,
        },
      });
    },
    //跳转登入
    logFn() {
      this.$router.push("/login");
    },
  },
  created() {
    //获取定位城市
    citie("guess").then((res) => {
      console.log(147, res);
      this.locationCity = res.data.name;
    });
    //获取热门城市
    citie("hot").then((res) => {
      console.log(res);
      this.topCity = res.data;
      console.log(this.topCity);
    });
    //获取所有城市
    citie("group").then((res) => {
      console.log(res);
      this.allCity = res.data;
      console.log(68, this.allCity);
    });
  },
};
</script>

<style lang="less" scoped>
body {
  margin: 0;
  padding: 0;
}
.box {
  background-color: #f5f5f5;
}
/deep/.van-nav-bar {
  background-color: #1989fa;
  .van-icon {
    color: #f5f5f5;
  }
}
.top {
  background-color: #fff;
  padding-top: 10px;
  border-bottom: 10px solid #eee;
  h3 {
    line-height: 35px;
    margin-left: 10px;
  }
  .top_citie {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    h5 {
      display: block;
      height: 20px;
      line-height: 20px;
    }
    span {
      text-align: center;
      display: block;
      width: 24%;
      height: 35px;
      line-height: 35px;
      border: 1px solid #e8e8e8;
      color: #1989fa;
    }
    span:hover {
      cursor: pointer;
    }
  }
}
.all {
  background-color: #fff;
  text-align: center;
  padding: 10px 0;
  h3 {
    line-height: 35px;
  }
  h1 {
    font-size: 1.875rem;
  }
  .all_citie {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    margin-bottom: 30px;

    h5 {
      display: block;
      height: 1.875rem;
      line-height: 1.875rem;
    }
    span {
      text-align: center;
      display: block;
      width: 24%;
      height: 3.125rem;
      line-height: 3.125rem;
      font-size: 1rem;
      margin: 0.3125rem 0;
      border: 0.0625rem solid #ccc;
      overflow: hidden;
      white-space: nowrap;
    }
    span:hover {
      cursor: pointer;
    }
  }
}
.van-cell:hover {
  cursor: pointer;
}
.van-icon {
  color: #f5f5f5;
}
.van-button {
  width: 100%;
}
.nontent {
  margin-bottom: 1.25rem;
}
.cnontent {
  border-bottom: 10px solid #eee;
}
</style>